<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: Author: HCZ <huangchengze@etrol.com> 
// +----------------------------------------------------------------------

namespace app\warning\controller\ajax;


class Assessment {
	
	/**
	 * 雷达图(企业预警系数)
	 */
	public function getRadarData($enterpriseId = null){
		$where = [];
		if($enterpriseId){
			$where['enterpriseId'] = $enterpriseId;
		}
		$warning = model('warning')->with('enterprise')->where($where)->find();
		$riskDegree = model('Config')->where('groupName','risk_degree')->order('name desc')->column('value','name');
		$indicator = [
				['name'=>'生产工艺','max'=>20],
				['name'=>'设备设施','max'=>20],
				['name'=>'工作环境','max'=>10],
				['name'=>'人员行为','max'=>20],
				['name'=>'管理体系','max'=>50],
		];	
		$radarData = [
				'title' => $warning['enterprise']['shortname'],
				'indicator' => $indicator,
				'id' => $warning['enterpriseId'],
				'color' => explode(",",$riskDegree[$warning['riskDegree']])[2],
				'data' => ['value'=>[
						(int)$warning['techniqueValue'],
						(int)$warning['equipmentValue'],
						(int)$warning['workingValue'],
						(int)$warning['behaviorValue'],
						(int)$warning['manageValue'],
				]],
		];
		return json(['code'=>1,'msg'=>'预警分数获取成功','data'=>$radarData]);
	}
	
	
	public function getLineData($enterpriseId = null){
		$where = [];
		if($enterpriseId){
			$where['enterpriseId'] = $enterpriseId;
		}
		
		$hisotry = model('Warninghistory')->where($where)->select();
		$riskDegree = model('Config')->where('groupName','risk_degree')->order('name desc')->column('value','name');
		$lineData = [];
		foreach($hisotry as $item){
			$lineData['technique'][] = (int)$item['techniqueValue'];
			$lineData['equipment'][] = (int)$item['equipmentValue'];
			$lineData['working'][] = (int)$item['workingValue'];
			$lineData['behavior'][] = (int)$item['behaviorValue'];
			$lineData['manage'][] = (int)$item['manageValue'];
			$lineData['date'][] = $item['createTime'];
		}
		
		return json(['code'=>1,'msg'=>'预警分数获取成功','data'=>$lineData]);
	}
	
}